/*   1:    */ package org.intellij.plugins.relaxNG.compact;
/*   2:    */ 
/*   3:    */

import com.intellij.codeInsight.daemon.EmptyResolveMessageProvider;
import com.intellij.codeInspection.*;
import com.intellij.lang.annotation.Annotation;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.Annotator;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPolyVariantReference;
import com.intellij.psi.PsiReference;
import org.intellij.plugins.relaxNG.compact.psi.*;
import org.jetbrains.annotations.NotNull;

import java.text.MessageFormat;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */ 
/*  25:    */ public class ReferenceAnnotator
/*  26:    */   extends RncElementVisitor
/*  27:    */   implements Annotator
/*  28:    */ {
/*  29:    */   private AnnotationHolder a;
/*  30:    */   
/*  31:    */   public synchronized void annotate(@NotNull PsiElement paramPsiElement, @NotNull AnnotationHolder paramAnnotationHolder)
/*  32:    */   {
/*  33: 43 */     if (paramPsiElement == null) {
/*  34: 43 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/compact/ReferenceAnnotator", "annotate" }));
/*  35:    */     }
/*  36: 43 */     if (paramAnnotationHolder == null) {
/*  37: 43 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/intellij/plugins/relaxNG/compact/ReferenceAnnotator", "annotate" }));
/*  38:    */     }
/*  39: 43 */     this.a = paramAnnotationHolder;
/*  40:    */     try
/*  41:    */     {
/*  42: 45 */       paramPsiElement.accept(this);
/*  43:    */     }
/*  44:    */     finally
/*  45:    */     {
/*  46: 47 */       this.a = null;
/*  47:    */     }
/*  48:    */   }
/*  49:    */   
/*  50:    */   public void visitInclude(RncInclude paramRncInclude)
/*  51:    */   {
/*  52: 53 */     a(paramRncInclude.getReferences());
/*  53:    */   }
/*  54:    */   
/*  55:    */   public void visitExternalRef(RncExternalRef paramRncExternalRef)
/*  56:    */   {
/*  57: 58 */     a(paramRncExternalRef.getReferences());
/*  58:    */   }
/*  59:    */   
/*  60:    */   public void visitRef(RncRef paramRncRef)
/*  61:    */   {
/*  62: 63 */     a(paramRncRef.getReferences());
/*  63:    */   }
/*  64:    */   
/*  65:    */   public void visitParentRef(RncParentRef paramRncParentRef)
/*  66:    */   {
/*  67: 68 */     a(paramRncParentRef.getReferences());
/*  68:    */   }
/*  69:    */   
/*  70:    */   public void visitName(RncName paramRncName)
/*  71:    */   {
/*  72: 73 */     a(paramRncName.getReferences());
/*  73:    */   }
/*  74:    */   
/*  75:    */   private void a(PsiReference[] paramArrayOfPsiReference)
/*  76:    */   {
/*  77: 77 */     for (PsiReference localPsiReference : paramArrayOfPsiReference) {
/*  78: 78 */       if ((!localPsiReference.isSoft()) && 
/*  79: 79 */         (localPsiReference.resolve() == null)) {
/*  80: 80 */         if ((localPsiReference instanceof PsiPolyVariantReference))
/*  81:    */         {
/*  82: 81 */           PsiPolyVariantReference localPsiPolyVariantReference = (PsiPolyVariantReference)localPsiReference;
/*  83: 82 */           if (localPsiPolyVariantReference.multiResolve(false).length == 0) {
/*  84: 83 */             a(localPsiReference);
/*  85:    */           }
/*  86:    */         }
/*  87:    */         else
/*  88:    */         {
/*  89: 86 */           a(localPsiReference);
/*  90:    */         }
/*  91:    */       }
/*  92:    */     }
/*  93:    */   }
/*  94:    */   
/*  95:    */   private void a(PsiReference paramPsiReference)
/*  96:    */   {
/*  97: 94 */     TextRange localTextRange1 = paramPsiReference.getRangeInElement();
/*  98: 95 */     TextRange localTextRange2 = TextRange.from(paramPsiReference.getElement().getTextRange().getStartOffset() + localTextRange1.getStartOffset(), localTextRange1.getLength());
/*  99:    */     Object localObject1;
/* 100:    */     Annotation localAnnotation;
/* 101: 99 */     if ((paramPsiReference instanceof EmptyResolveMessageProvider))
/* 102:    */     {
/* 103:100 */       localObject1 = ((EmptyResolveMessageProvider)paramPsiReference).getUnresolvedMessagePattern();
/* 104:101 */       localAnnotation = this.a.createErrorAnnotation(localTextRange2, MessageFormat.format((String)localObject1, new Object[] { paramPsiReference.getCanonicalText() }));
/* 105:    */     }
/* 106:    */     else
/* 107:    */     {
/* 108:104 */       localAnnotation = this.a.createErrorAnnotation(localTextRange2, "Cannot resolve symbol");
/* 109:    */     }
/* 110:106 */     localAnnotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
/* 111:108 */     if ((paramPsiReference instanceof LocalQuickFixProvider))
/* 112:    */     {
/* 113:109 */       localObject1 = ((LocalQuickFixProvider)paramPsiReference).getQuickFixes();
/* 114:110 */       if (localObject1 != null)
/* 115:    */       {
/* 116:111 */         InspectionManager localInspectionManager = InspectionManager.getInstance(paramPsiReference.getElement().getProject());
/* 117:112 */         for (LocalQuickFix localLocalQuickFix : localObject1)
/* 118:    */         {
/* 119:113 */           ProblemDescriptor localProblemDescriptor = localInspectionManager.createProblemDescriptor(paramPsiReference.getElement(), localAnnotation.getMessage(), localLocalQuickFix, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, true);
/* 120:    */           
/* 121:115 */           localAnnotation.registerFix(localLocalQuickFix, null, null, localProblemDescriptor);
/* 122:    */         }
/* 123:    */       }
/* 124:    */     }
/* 125:    */   }
/* 126:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.compact.ReferenceAnnotator

 * JD-Core Version:    0.7.0.1

 */